local _G = GLOBAL
local containers = require("containers")
local params = {}

-- 兼容模组"Show Me (中文)"的容器列表
local showmeneed = {
    "sw_pig_cannon",
}

--================================
--[[注册容器:猪猪炮]]
--================================
params.sw_pig_cannon =
{
    widget =
    {
        slotpos =
        {
            Vector3(0, 32 + 4, 0),
        },
        slotbg =
        {
            { image = "inv_slot_dragonflyfurnace.tex", atlas = "images/hud2.xml" },
        },
        animbank = "ui_cookpot_1x2",
        animbuild = "ui_cookpot_1x2",
        pos = Vector3(0, 15, 0),
    },
    type = "hand_inv",
    excludefromcrafting = true, -- 容器内的物品不会被用于制作
}

function params.sw_pig_cannon.itemtestfn(container, item, slot)
    return item:HasTag("sw_piggy_bomb")
end

--================================
--[[修改容器注册函数]]
--================================
for k, v in pairs(params) do
    containers.params[k] = v

    -- 更新容器格子数量的最大值
    containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, v.widget.slotpos ~= nil and #v.widget.slotpos or 0)
end
params = nil -- 释放内存

--================================
--[[mod兼容：Show Me (中文)]]
--================================
-- showme优先级如果比本mod高，那么这部分代码会生效
for k, mod in pairs(ModManager.mods) do
    if mod and _G.rawget(mod, "SHOWME_STRINGS") then -- showme特有的全局变量
        if
            mod.postinitfns and mod.postinitfns.PrefabPostInit and
            mod.postinitfns.PrefabPostInit.treasurechest
        then
            for _, v in ipairs(showmeneed) do
                mod.postinitfns.PrefabPostInit[v] = mod.postinitfns.PrefabPostInit.treasurechest
            end
        end
        break
    end
end

-- showme优先级如果比本mod低，那么这部分代码会生效
TUNING.MONITOR_CHESTS = TUNING.MONITOR_CHESTS or {}
for _, v in ipairs(showmeneed) do
    TUNING.MONITOR_CHESTS[v] = true
end
